﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace OpenQuarters.WebQuarters.Core
{
    [global::System.AttributeUsage(AttributeTargets.Property, Inherited = true, AllowMultiple = false)]
    public sealed class OrderableAttribute : Attribute
    {
        public OrderableAttribute()
        {
        }

        public static List<string> GetOrderableFields(Type type)
        {
            var l = new List<string>();
            if (type != null)
            {
                type
                    .GetProperties()
                    .Where(e => e.GetCustomAttributes(typeof(OpenQuarters.WebQuarters.Core.OrderableAttribute), true).Count() > 0)
                    .ToList()
                    .ForEach(e => l.Add(e.Name));
            }
            l.Sort();
            return l;
        }
    }
}
